<?xml version="1.0" encoding="UTF-8" ?>
<%@ page import="java.util.Collection" %>
<%@page import="landmark.LandmarkUtente"%>
<%@page import="landmark.LandmarkVisit"%>
<%@page import="landmark.Link"%>
<%@ page import="org.swimv2.model.Persona" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<script type="text/javascript">
function disable(op){
if(op=='abUt'){


document.getElementById("buttonAb").style.display="none";
document.getElementById("buttonCred").style.display="inline";

	}
else if(op=='credUt'){


document.getElementById("buttonCred").style.display="none";
document.getElementById("buttonAb").style.display="inline";


	}
else if(op=='NomeCognome') {
		document.getElementById("nome").disabled=true;
		document.getElementById("cognome").disabled=true;
		document.getElementById("usernameId").disabled=false;
		document.getElementById("nome").value="";
		document.getElementById("cognome").value="";
	}
else if(op=='Username') {
		document.getElementById("nome").disabled=false;
		document.getElementById("cognome").disabled=false;
		document.getElementById("usernameId").disabled=true;
		document.getElementById("usernameId").value="";
	}


}
</script>
<script language="Javascript">
function isnum(obj) {

if (isNaN(obj.value) || parseInt(obj.value)<1 || parseInt(obj.value) > 100 || obj.value=="")

{

alert('Nel campo è possibile immettere solo numeri compresi tra 1 e 100!');
obj.value="";
obj.focus();
}

}


function includeAmici(){
		
			
	
	if(document.getElementById("amici").checked==true){
		document.getElementById("amici").value="si";
		
	}

	}

</script>




<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Ricerca utente</title>
<link rel="stylesheet" type="text/css" href="scheletro.css">
</head>
<body>
<div id="container">
<table class="topHome">
	<tr>
		    <td id="logoHome">
	<a href="home.jsp">Swim v2</a>
	<br><br><b> A help with a click!</b>

		    </td>
				<td class="personal">
				
					<% if (request.getSession().getAttribute("utente")!=null){ 
					Persona u =(Persona) request.getSession().getAttribute("utente"); 
					if (u.getRuolo().equals("UTENTE")){ %>
					
					<b>Ciao :<a href="PaginaProfiloServlet">${sessionScope.utente.nome}</a> </b>&nbsp;&nbsp;&nbsp;<a href="Notifiche"><b>Interazioni</b></a>&nbsp;<a href="messaggi.jsp"><b>Messaggi</b></a>&nbsp;&nbsp;&nbsp;<div id="button"><a href="Logout" id="logout">Logout</a></div>
				<% } 
					
					else {%>
					<b>Ciao :<a href="paginaAmministratore.jsp">${sessionScope.utente.nome}</a> </b>&nbsp;&nbsp;&nbsp;<a href="NotificheAbServlet"><b>Notifiche</b></a>&nbsp;<a href="messaggiRicevuti.jsp"><b>Messaggi</b></a>&nbsp;<a href="GestioneAbServlet"><b>Modifica abilità</b></a>
					<br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;<div id="button"><a href="Logout" id="logout">Logout</a></div>	
				<%	}
					}
				%>	
				
				<% if(request.getSession().getAttribute("utente")==null){ %>
				<form action="Login" method="post" onsubmit="return check()">
						<b>Username:</b> <input type="text"  name="username" id="username">
				
						<b>Password:</b> <input type="password" name="password" id="password">
						
						<input id="button" type="submit" name="Login" value="login">
						<br><br>
						<b>Sei un nuovo utente?</b>&nbsp;<a href="Registrazione">Registrati</a>
				</form>
				<% } %>
			</td>		
	</tr>
</table>

<% if (request.getSession().getAttribute("utente")!=null)
	{ %>
	<div id="nav"> 
		<ul>
			<%
				Link a[]  = LandmarkUtente.getLandmark();
				for(int i=0; i<a.length; i++)
				{
			%>
				<%
					if(a[i].getValue().equalsIgnoreCase("Ricerca"))
					{
				%>
					<li><a href="<%=a[i].getHref() %>"><u><%=a[i].getValue() %></u></a></li>
				<%	}
				%>
				
				<%	if(!a[i].getValue().equalsIgnoreCase("Ricerca"))
					{
				%>
					<li><a href="<%=a[i].getHref() %>"><%=a[i].getValue() %></a></li>
				<%} 
				%>
			<%} 
			%>
		</ul>
	</div>
<%} %>

<% if (request.getSession().getAttribute("utente")==null)
	{ %>
	<div id="nav"> 
		<ul>
			<%
				Link a[]  = LandmarkVisit.getLandmark();
				for(int i=0; i<a.length; i++)
				{
			
					if(a[i].getValue().equalsIgnoreCase("Ricerca"))
					{
				%>
					<li><a href="<%=a[i].getHref() %>"><u><%=a[i].getValue() %></u></a></li>
				<%	}
					if(!a[i].getValue().equalsIgnoreCase("Ricerca"))
					{
				%>
					<li><a href="<%=a[i].getHref() %>"><%=a[i].getValue() %></a></li>
				<%} 
				
				} 
			%>
		</ul>
	</div>
<%} %>
	

<div id="form">
	<div id="titlePage"><h1>Ricerca utente</h1></div><br><br>
			
			<form>
			    <fieldset>
			                
			        <label for="tipoRicerca">Quale tipo di ricerca desideri effettuare?</label> <br><br>
			        <b>Credenziali utente</b><input type="radio" name="ricerca" value="credUt" onclick="disable('abUt')"/>
			        <b>Abilità</b><input type="radio" name="ricerca" value="abilUt" onclick="disable('credUt')"/>
			    </fieldset>
			</form>
			<br><br><br>
		
		<div id="buttonCred" style="display:none">
		  <fieldset>
		   <b>Ricerca per Credenziali utente:</b> <br><br>
			<form>
				    
				                
				        <label for="tipoRicerca">seleziona una delle due opzioni:</label> <br><br>
				        <b>Nome e Cognome</b><input type="radio" name="ricerca" value="nomeCognome" onclick="disable('Username')"/>
				        <b>Username</b><input type="radio" name="ricerca" value="userId" onclick="disable('NomeCognome')"/>
				    
				</form>
				<br><br><br>
			
			<form name="perCred" action="RicercaCredenziali" method="post">
			   
			  	
			 	 <br><br>
			  	
			                <label for="nome">Nome</label>&nbsp;&nbsp;&nbsp;&nbsp;
			                <input type="text" name="nome" id="nome" disabled="disabled"/> 
			                
			        		<label for="cognome">Cognome</label>&nbsp;
			                <input type="text" name="cognome" id="cognome" disabled="disabled"/><br><br>
			                
			          		<label for="username">Username</label>
			                <input type="text" name="usernameId" id="usernameId" disabled="disabled"/><br><br>
			                
			                <input type="submit" name="submit" id="button" value="Cerca" />
				
			
			</form>
			</fieldset>
		</div>
			<br><br>
		
		<div id="buttonAb" style="display:none">
			<form name="perAbilit" action="RicercaAb" method="post"  onsubmit="includeAmici()">
			   <fieldset>
			  	<b>Ricerca utente per abilità:</b>
			 	 <br><br>
					<%
						@SuppressWarnings("unchecked")
						Collection<String> listAb= (Collection<String>) request.getAttribute("listAb");	 %>		
							<label for="titolo">Abilità</label>
			                &nbsp;&nbsp;&nbsp;
			                <select name="opAbilit" id="opAbilit">
			                <%
								for(String s: listAb) {
							
									%>
			                
			                	<option value="<%=s %>"><%= s %></option>
			                	<% } %>
			               	</select> 
							&nbsp;&nbsp;&nbsp;&nbsp;
							<label for="titolo">Disponibilità minima </label>
			                
			                <input type="text" name="disp" id="disp" value="0" onBlur="isnum(this)" size="4"/>
			                	
			                	
			                
							 <br><br> 	
							<label for="regione">Regione d'Italia</label>
			                <select name="regione" id="regione">
			                	  	
			                	  	<option value="All">All</option>
				                	<option value="Abruzzo">Abruzzo</option>
				                	<option value="Basilicata">Basilicata</option>
				                	<option value="Calabria">Calabria</option>
				                	<option value="Campania">Campania</option>
				                	<option value="Emilia Romagna">Emilia Romagna</option>
				                	<option value="Friuli-Venezia-Giulia">Friuli-Venezia-Giulia</option>
				                	<option value="Lazio">Lazio</option>
				                	<option value="Liguria">Liguria</option>
				                	<option value="Lombardia">Lombardia</option>
				                	<option value="Marche">Marche</option>
				                	<option value="Molise">Molise</option>
				                	<option value="Piemonte">Piemonte</option>
				                	<option value="Puglia">Puglia</option>
				                	<option value="Sardegna">Sardegna</option>
				                	<option value="Sicilia">Sicilia</option>
				                	<option value="Toscana">Toscana</option>
				                	<option value="Trentino Alto-Adige">Trentino Alto-Adige</option>
				                	<option value="Umbria">Umbria</option>
				                	<option value="Valle d'Aosta">Valle d'Aosta</option>
				                	<option value="Veneto">Veneto</option>
							 </select>
			                
			              <br><br>
			               <% if(request.getSession().getAttribute("utente")!=null){ %>
			                <b>Desideri restringere la ricerca ai soli amici?</b><input name="amici" type="checkbox" value="no" id="amici"/>                           
			                
						   <% } %>
						   
						   <input type="submit" name="submit" id="button" value="Cerca"/>
				</fieldset>
			
			</form>
		</div>

</div>
</div>
</body>
</html>